package one.stand.controller;

import com.jmp.api.user.dto.DataCountAddConsultRecordRequest;
import com.jmp.api.user.dto.RecordAddCallsPhoneRecordRequest;
import com.jmp.autocofiguration.web.interceptor.SecurityAuthCheck;
import com.jmp.base.dto.RecordCallRequest;
import com.jmp.base.dto.RecordConsultRequest;
import com.jmp.feign.RecordFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import one.stand.model.ResultModel;
import one.stand.request.DynamicForwardRecordRequest;
import one.stand.request.GoodsForwardRecordRequest;
import one.stand.request.RoyaltyRecordRequest;
import one.stand.util.AssertUtil;
import one.stand.util.RequestContext;
import one.stand.util.RequestContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 产品信息查询
 *
 * @author Administrator
 */
@RestController
@RequestMapping("userApi/record")
@Api(description = "添加记录系列")
public class RecordController extends BaseController {
    @Autowired
    private RecordFeign recordFeign;

    @ApiOperation(value = "添加咨询(聊天)记录")
    @PostMapping("/addConsultRecord")
    @SecurityAuthCheck
    public ResultModel addConsultRecord(@RequestAttribute DataCountAddConsultRecordRequest request) {
        RequestContext.User user = RequestContextHolder.getRequestContext().getUser();
        ResultModel resultModel = recordFeign.consult(RecordConsultRequest.builder()
                .userId(user.getUserId())
                .cardId(request.getCardId())
                .type(request.getSonsultType())
                .build());
        AssertUtil.isTrue(resultModel);
        return ResultModel.success(true);
    }

    @PostMapping("/addGoodsForwardRecord")
    @ApiOperation(value = "添加商品转发记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cardId", value = "入口名片id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "goodsId", value = "商品ID", required = true, paramType = "Integer"),
    })
    @SecurityAuthCheck
    public ResultModel<Integer> addGoodsForwardRecord(@RequestAttribute GoodsForwardRecordRequest request) {
        return userFegin.addGoodsForwardRecord(request);
    }

    @ApiOperation(value = "使商品转发记录有效")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "forwardId", value = "商品转发记录id", required = true, paramType = "Integer"),
    })
    @PostMapping("validGoodsForwardRecord")
    @SecurityAuthCheck
    public ResultModel<Boolean> validGoodsForwardRecord(@RequestAttribute GoodsForwardRecordRequest request) {
        return userFegin.validGoodsForwardRecord(request);
    }

    @PostMapping("/addDynamicForwardRecord")
    @ApiOperation(value = "添加文章转发记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cardId", value = "入口名片id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "dynamicId", value = "文章/动态ID", required = true, paramType = "Integer"),
    })
    @SecurityAuthCheck
    public ResultModel addDynamicForwardRecord(@RequestAttribute DynamicForwardRecordRequest request) {
        return userFegin.addDynamicForwardRecord(request);
    }

    @ApiOperation(value = "添加拨打电话记录")
    @PostMapping("/addCallsPhoneRecord")
    @SecurityAuthCheck
    public ResultModel<Boolean> addCallsPhoneRecord(@RequestAttribute RecordAddCallsPhoneRecordRequest request) {
        RequestContext.User user = RequestContextHolder.getRequestContext().getUser();
        ResultModel resultModel = recordFeign.call(RecordCallRequest.builder().userId(user.getUserId()).cardId(request.getCardId()).build());
        AssertUtil.isTrue(resultModel);

        return ResultModel.success(true);
    }

    @PostMapping("/selectRoyaltyRecord")
    @ApiOperation(value = "佣金/提现列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "1佣金记录，2提现记录", required = true, paramType = "Integer"),
    })
    @SecurityAuthCheck
    public ResultModel<Map<String, Object>> selectRoyaltyRecord(@RequestAttribute RoyaltyRecordRequest request) {
        return userFegin.selectRoyaltyRecord(request);
    }

    @PostMapping("/doCash")
    @ApiOperation(value = "提现操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "royaltyMoney", value = "提现金额", required = true, paramType = "Integer"),
    })
    @SecurityAuthCheck
    public ResultModel<Boolean> doCash(@RequestAttribute RoyaltyRecordRequest request) {
        return userFegin.doCash(request);
    }
}
